﻿@{

    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>生产退料列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
    <link href="~/scripts/layui-v2.5.6/layui/css/layui.mobile.css" rel="stylesheet" />
    <link href="~/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <script src="~/scripts/jquery-3.4.1.min.js"></script>
</head>
<body>

    <script type="text/html" id="toolbarDemo">


        <div class="layui-inline">
            退料单编号:
             <div  class="layui-inline">
              <input type="text" id="ItemCode" value="" placeholder="请输入退料单编号" class="layui-input" lay-affix="clear">
            </div>
            生产工单:
            <div  class="layui-inline">
               <input type="text" id="BatchCode" placeholder="请输入生产工单" lay-affix="clear" class="layui-input">
            </div>
             仓库名称:
             <div  class="layui-inline">
                <input type="text" id="WareHouseName" placeholder="请输入仓库名称" lay-affix="clear" class="layui-input">
             </div>
             <button class="layui-btn" lay-submit lay-filter="demo-table-search">搜索</button>
             <button type="reset" class="layui-btn layui-btn-primary">重置</button>
             <button type="button" class="layui-btn layui-btn layui-btn-success" lay-on="test-page-custom">
                  <i class="layui-icon layui-icon-add-1"></i>添加
              </button>
        </div>

    </script>

    <!--表格-->
    <div style="padding: 16px;">
        <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>

    <!--操作列-->
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(['table', 'dropdown'], function () {
            var table = layui.table;
            var dropdown = layui.dropdown;
            var layer = layui.layer;
            var util = layui.util;

            //*********************显示**********************/
            function show() {

                table.render({
                    elem: '#test',
                    url: '/Meng/GetRtIssue', // 此处为静态模拟数据，实际使用时需换成真实接口
                    toolbar: '#toolbarDemo',
                    height: 'full-35', // 最大高度减去其他容器已占有的高度差
                    css: [ // 重设当前表格样式
                        '.layui-table-tool-temp{padding-right: 145px;}'
                    ].join(''),
                    cellMinWidth: 80,
                    page: true,
                    limit: 10,
                    limits: [10, 20, 50, 100],
                    request: {
                        pageName: 'page', //页码的参数名称，默认：page
                        limitName: 'limit' //每页数据量的参数名，默认：limit
                    },
                    cols: [[
                        { type: 'checkbox', fixed: 'left' },
                        { field: 'ItemCode', fixed: 'left', width: 120, title: '退料单编号', sort: true, totalRow: '合计：' },
                        { field: 'ItemName', title: '退料单名称' },
                        { field: 'BatchCode', title: '生产工单' },
                        { field: 'WarehouseName', title: '仓库名称' },
                        { field: 'LocationName', title: '库区名称' },
                        { field: 'AreaName', title: '库位名称' },
                        { fixed: 'right', title: '操作', templet: '#barDemo' }
                    ]],

                });

            }
            show();


            // ************************搜索提交**************************
            var form = layui.form;
            form.on('submit(demo-table-search)', function (data) {
                var field = data.field; // 获得表单字段
                // 执行搜索重载
                var itemCode = $("#ItemCode").val();
                var batchCode = $("#BatchCode").val();
                var wareHouseName = $("#WareHouseName").val();
                table.reload('test', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    },
                    where: {
                        itemCode: itemCode,
                        batchCode: batchCode,
                        wareHouseName: wareHouseName
                    }
                });
                layer.msg('搜索成功');
                return false; // 阻止默认 form 跳转
            });

            //********************添加********************
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 2,
                        title: '添加生产退料',
                        skin: 'layui-layer-rim', //加上边框
                        area: ['60%', '60%'], //宽高
                        content: '/Meng/AddOutSourceView',//////////////添加页面
                        end: function () {
                            show();//刷新父级页面列表方法，类似于回调函数
                        }
                    });
                }
            })

            //*****************************修改,删除************************ */
            //表单操作
            table.on('tool(test)', function (obj) {

                if (obj.event === 'edit') {
                    var data = obj.data;
                    /////数据传到子页面
                    Id = data.Id;
                    IssueId = data.IssueId;
                    ItemId = data.ItemId;
                    ItemCode = data.ItemCode;
                    ItemName = data.ItemName;
                    Specification = data.Specification;
                    UnitOfMeasure = data.UnitOfMeasure;
                    QuantityIssued = data.QuantityIssued;
                    BatchCode = data.BatchCode;
                    WarehouseId = data.WarehouseId;
                    WarehouseCode = data.WarehouseCode;
                    WarehouseName = data.WarehouseName;
                    LocationId = data.LocationId,
                    LocationCode = data.LocationCode,
                    LocationName = data.LocationName,
                    AreaId = data.AreaId,
                    AreaCode = data.AreaCode,
                    AreaName = data.AreaName,
                    Remark = data.Remark,
                    Remark = data.Remark,
                    CreateBy = data.CreateBy,
                    CreateTime = data.CreateTime

                    layer.open({
                        type: 2, // page 层类型
                        area: ['60%', '60%'],
                        title: '修改生产退料',
                        shade: 0.6, // 遮罩透明度
                        shadeClose: true, // 点击遮罩区域，关闭弹层
                        maxmin: true, // 允许全屏最小化
                        anim: 0, // 0-6 的动画形式，-1 不开启
                        content: '/Meng/UpdateOutSourceView',
                        end: function () {
                            show();//刷新父级页面列表方法，类似于回调函数
                        }
                    });
                }

                else if (obj.event === 'delete') {
                    if (!confirm('确定删除吗？')) return;
                    $.ajax({
                        url: '/Meng/DeleteRtIssue', // 替换为你的API URL
                        type: 'GET',
                        data: { id: obj.data.Id },
                        dataType: 'json',
                        success: function (res) {
                            if (res != null) {
                                alert("删除成功");
                                window.location.href = "/Meng/OutSourceView/"
                            }
                        }
                    });
                }
            })


        });


    </script>
</body>
</html>